package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.dto.*;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.support.RpcUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;

@RestController
@Anoymous
@RequestMapping("/shopping")
public class IProductController {
    @Reference(timeout = 3000,check = false)
    IProductService productService;


    @GetMapping("/product/{id}")
    public ResponseData searchDetailById(@PathVariable(name = "id")Long id){
        ProductDetailRequest detailRequest = new ProductDetailRequest();
        detailRequest.setId(id);
        ProductDetailResponse detailResponse = productService.getProductDetail(detailRequest);
        return new ResponseUtil<>().setData(detailResponse.getProductDetailDto());
    }
    /*
    商品详情
     */
    @GetMapping("/goods")
    public ResponseData getAllGoods(Integer page,Integer size,String sort,Long cid,Integer priceGt,Integer priceLte){
        AllProductRequest allProductRequest = new AllProductRequest(page,size,sort,cid,priceGt,priceLte);
        AllProductResponse response = productService.getAllProduct(allProductRequest);
        LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>();
        responseMap.put("data",response.getProductDtoList());
        responseMap.put("total",response.getTotal());
        return new ResponseUtil<>().setData(responseMap);

    }
    @GetMapping("/recommend")
    public ResponseData searchRecommend(){
        RecommendResponse response = productService.getRecommendGoods();
        return new ResponseUtil<>().setData(response.getPanelContentItemDtos());
    }
}
